//
//  MyselfViewController.m
//  FruitVIP
//
//  Created by 孙艳玲 on 15/5/21.
//  Copyright (c) 2015年 孙艳玲. All rights reserved.
//

#import "MyselfViewController.h"
#import "AppDelegate.h"

#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

@interface MyselfViewController ()<UIApplicationDelegate>
{

  UIImageView *navBarHairlineImageView;
}

@end

@implementation MyselfViewController

- (void)viewDidAppear:(BOOL)animated

{
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;    //让rootView禁止滑动
        
    }
      self.navigationItem.hidesBackButton = YES;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
//    self.navigationController.navigationBar.hidden = YES;
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBarHidden = NO;
    self.navigationItem.hidesBackButton = YES;
      navBarHairlineImageView.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
     navBarHairlineImageView.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"个人中心";
     [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:110.0 / 255.0 green:78.0 / 255.0 blue:71.0 / 255.0 alpha:1]}];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:255.0/255.0 green:206.0 / 255.0 blue:0 / 255.0 alpha:1];


    //添加导航栏图片

    
    
    self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 49-64  ) style:UITableViewStylePlain];
    self.myTableView.backgroundColor = [UIColor whiteColor];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    [self.view addSubview:self.myTableView];
//     self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0, self.myTableView.frame.origin.y + self.myTableView.frame.size.height, SCREEN_WIDTH, 49)];
    footView.backgroundColor = [UIColor colorWithRed:15.0/255.0 green:17.0/255.0 blue:30.0/255.0 alpha:1];;
    [self.view addSubview:footView];
    
    
    UIButton *firstButton = [UIButton buttonWithType:UIButtonTypeCustom];
    firstButton.frame = CGRectMake(40, 0, 40, 40);
    [firstButton setImage:[UIImage imageNamed:@"shouye.png"] forState:UIControlStateNormal];
    [firstButton addTarget:self action:@selector(firstButtonAction) forControlEvents:UIControlEventTouchUpInside];
    self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:0];
    [footView addSubview:firstButton];
    
    UIButton *secondButton = [UIButton buttonWithType:UIButtonTypeCustom];
    secondButton.frame = CGRectMake(firstButton.frame.origin.x + firstButton.frame.size.width + 60, firstButton.frame.origin.y, 40, 40);
    [secondButton setImage:[UIImage imageNamed:@"car.png"] forState:UIControlStateNormal];
    [secondButton addTarget:self action:@selector(secondButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [footView addSubview:secondButton];
    
    UIButton *thirdButton = [UIButton buttonWithType:UIButtonTypeCustom];
    thirdButton.frame = CGRectMake(secondButton.frame.origin.x + secondButton.frame.size.width + 60, secondButton.frame.origin.y, 40, 40);
    [thirdButton setImage:[UIImage imageNamed:@"me_higt.png"] forState:UIControlStateNormal];
    [thirdButton addTarget:self action:@selector(thirdButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [footView addSubview:thirdButton];

//隐藏导航栏下划线
    navBarHairlineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
    
}

//实现找出底部横线的函数
- (UIImageView *)findHairlineImageViewUnder:(UIView *)view {
    if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
        return (UIImageView *)view;
    }
    for (UIView *subview in view.subviews) {
        UIImageView *imageView = [self findHairlineImageViewUnder:subview];
        if (imageView) {
            return imageView;
        }
    }
    return nil;
}


- (void)firstButtonAction
{
    
    [self.navigationController popToRootViewControllerAnimated:NO];
    self.tabBarController.tabBar.hidden = YES;
}
- (void)secondButtonAction
{
    
    
    self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:1];
}
- (void)thirdButtonAction
{
    self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:2];
    self.tabBarController.tabBar.hidden = YES;
    

    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 7;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//    static NSString *cellIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
    }
       //显示右侧箭头
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    if (indexPath.row == 0) {
        
        UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH/3)];
        headView.backgroundColor = [UIColor colorWithRed:255.0/255.0 green:206.0 / 255.0 blue:0 / 255.0 alpha:1];
        [cell addSubview:headView];
        
        
        UIImageView *headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(2 * SCREEN_WIDTH/5, 0, SCREEN_WIDTH/5, SCREEN_WIDTH/3 - 40)];
//        headImageView.backgroundColor = [UIColor clearColor];
        UIImage *headImage = [UIImage imageNamed:@"head.png"];
        headImageView.image = headImage;
//        headImageView.backgroundColor = [UIColor redColor];
        headImageView.contentMode = UIViewContentModeScaleAspectFit;
        [headView addSubview:headImageView];

        UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/5,headImageView.frame.origin.y +  headImageView.frame.size.height + 10, headImageView.frame.size.width/2, headImageView.frame.size.height/4)];
        nameLabel.text = @"账户";
//        nameLabel.backgroundColor = [UIColor redColor];
        nameLabel.textColor = [UIColor colorWithRed:95.0/255.0 green:45.0/255.0 blue:24.0/255.0 alpha:1];
        nameLabel.font = [UIFont systemFontOfSize:13];
        [headView addSubview:nameLabel];
        
        
       
        UILabel *detailName = [[UILabel alloc] initWithFrame:CGRectMake(nameLabel.frame.origin.x + nameLabel.frame.size.width + 5, nameLabel.frame.origin.y, SCREEN_WIDTH/3.5, nameLabel.frame.size.height)];
        detailName.text = @"18717844083";
        detailName.textColor = [UIColor whiteColor];
        detailName.font = [UIFont systemFontOfSize:13];
//        detailName.backgroundColor = [UIColor redColor];
        [headView addSubview:detailName];
        
        UILabel *integralLabel = [[UILabel alloc] initWithFrame:CGRectMake(detailName.frame.origin.x + detailName.frame.size.width + 10, nameLabel.frame.origin.y , nameLabel.frame.size.width, nameLabel.frame.size.height)];
        integralLabel.text = @"积分";
        integralLabel.textColor = [UIColor colorWithRed:95.0/255.0 green:45.0/255.0 blue:24.0/255.0 alpha:1];
        integralLabel.font = [UIFont systemFontOfSize:13];
        [headView addSubview:integralLabel];
        
        UILabel *detailInteg = [[UILabel alloc] initWithFrame:CGRectMake(integralLabel.frame.origin.x + integralLabel.frame.size.width + 5, integralLabel.frame.origin.y, detailName.frame.size.width, detailName.frame.size.height)];
        detailInteg.text = @"100";
        detailInteg.textColor = [UIColor whiteColor];
        detailInteg.font = [UIFont systemFontOfSize:13];
        [headView addSubview:detailInteg];
        
        
        UIView *imageView = [[UIView alloc] initWithFrame:CGRectMake(0, headView.frame.origin.y + headView.frame.size.height, SCREEN_WIDTH, 70)];
        imageView.backgroundColor = [UIColor colorWithRed:255.0/255.0 green:206.0 / 255.0 blue:0 / 255.0 alpha:1];
        [cell addSubview:imageView];
        
        
        UIImageView *payImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH / 3, 70)];
        payImageView.backgroundColor = [UIColor colorWithRed:255.0/255.0 green:206.0 / 255.0 blue:0 / 255.0 alpha:1];
        ;
        //        payImageView.backgroundColor = [UIColor redColor];
        payImageView.userInteractionEnabled = YES;
        [imageView addSubview:payImageView];
        
        
        UIImageView *topPay = [[UIImageView alloc] initWithFrame:CGRectMake(payImageView.frame.size.width / 3.5, payImageView.frame.size.height/7, payImageView.frame.size.width/3, payImageView.frame.size.height/2)];
        //        topPay.backgroundColor = [UIColor redColor];
        UIImage *payImage = [UIImage imageNamed:@"waitpay.png"];
        topPay.image = payImage;
        topPay.contentMode = UIViewContentModeScaleAspectFit;
        [payImageView addSubview:topPay];
        
        UILabel *payLabel = [[UILabel alloc] initWithFrame:CGRectMake(payImageView.frame.size.width / 4, topPay.frame.origin.y + topPay.frame.size.height + 2, payImageView.frame.size.width / 2.5, payImageView.frame.size.height / 4)];
        payLabel.text = @"待付款";
        payLabel.font = [UIFont systemFontOfSize:13];
        //        payLabel.backgroundColor = [UIColor yellowColor];
        payLabel.textAlignment = NSTextAlignmentCenter;
        [payImageView addSubview:payLabel];
        
        UITapGestureRecognizer *payTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(payTapAction)];
        [payImageView addGestureRecognizer:payTap];
        
        UIImageView *deliverImage = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 3, payImageView.frame.origin.y, SCREEN_WIDTH/ 3, payImageView.frame.size.height)];
        deliverImage.backgroundColor = [UIColor colorWithRed:255.0/255.0 green:206.0 / 255.0 blue:0 / 255.0 alpha:1];
        deliverImage.userInteractionEnabled = YES;
        [imageView addSubview:deliverImage];
        
        UIImageView *deliver = [[UIImageView alloc] initWithFrame:CGRectMake(deliverImage.frame.size.width / 3.5, deliverImage.frame.size.height/7, deliverImage.frame.size.width/3, deliverImage.frame.size.height/2)];
        UIImage *deliverI = [UIImage imageNamed:@"deliver.png"];
        deliver.image = deliverI;
        deliver.contentMode = UIViewContentModeScaleAspectFit;
        //        deliver.backgroundColor = [UIColor redColor];
        [deliverImage addSubview:deliver];
        
        UILabel *deliverLabel = [[UILabel alloc] initWithFrame:CGRectMake(deliverImage.frame.size.width / 4, deliver.frame.origin.y + deliver.frame.size.height + 2, deliverImage.frame.size.width / 2.5, deliverImage.frame.size.height / 4)];
        deliverLabel.text = @"待发货";
        deliverLabel.font = [UIFont systemFontOfSize:13];
        deliverLabel.textAlignment = NSTextAlignmentCenter;
        [deliverImage addSubview:deliverLabel];
        
        
        UITapGestureRecognizer *deliverTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(deliverTapAction)];
        [deliverImage addGestureRecognizer:deliverTap];
        
        
        UIImageView *takeImage = [[UIImageView alloc] initWithFrame:CGRectMake(deliverImage.frame.origin.x + deliverImage.frame.size.width, payImageView.frame.origin.y, SCREEN_WIDTH / 3, deliverImage.frame.size.height)];
        takeImage.backgroundColor = [UIColor colorWithRed:255.0/255.0 green:206.0 / 255.0 blue:0 / 255.0 alpha:1];
        takeImage.userInteractionEnabled = YES;
        [imageView addSubview:takeImage];
        
        
        UIImageView *take = [[UIImageView alloc] initWithFrame:CGRectMake(takeImage.frame.size.width / 3.5, takeImage.frame.size.height/7, takeImage.frame.size.width/3, takeImage.frame.size.height/2)];
        UIImage *takeI = [UIImage imageNamed:@"take.png"];
        take.image = takeI;
        take.contentMode = UIViewContentModeScaleAspectFit;
        //        take.backgroundColor = [UIColor redColor];
        [takeImage addSubview:take];
        
        
        UILabel *takeLabel = [[UILabel alloc] initWithFrame:CGRectMake(takeImage.frame.size.width / 4, take.frame.origin.y + take.frame.size.height + 2, takeImage.frame.size.width / 2.5, takeImage.frame.size.height / 4)];
        takeLabel.text = @"待提货";
        takeLabel.font = [UIFont systemFontOfSize:13];
        takeLabel.textAlignment = NSTextAlignmentCenter;
        [takeImage addSubview:takeLabel];
        
        UITapGestureRecognizer *takeTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(takeTapAction)];
        [takeImage addGestureRecognizer:takeTap];

        
        cell.accessoryType = UITableViewCellAccessoryNone;
       
       
        
    }
    
            if (indexPath.row == 1) {
        UIImageView *allOrder = [[UIImageView alloc] initWithFrame:CGRectMake(15, 10, 28, 28)];
        UIImage *allImage = [UIImage imageNamed:@"allorder.png"];
        allOrder.image = allImage;
        allOrder.contentMode = UIViewContentModeScaleAspectFit;
        [cell addSubview:allOrder];

        UILabel *allOrderLabel = [[UILabel alloc] initWithFrame:CGRectMake(allOrder.frame.origin.x + allOrder.frame.size.width + 10, allOrder.frame.origin.y, SCREEN_WIDTH - allOrder.frame.size.width - 30, allOrder.frame.size.height)];
        allOrderLabel.text = @"所有订单";
        allOrderLabel.font = [UIFont systemFontOfSize:15];
        [cell addSubview:allOrderLabel];
         
         
    }
    if (indexPath.row == 2) {

        UIImageView *allOrder = [[UIImageView alloc] initWithFrame:CGRectMake(15, 10, 28, 28)];
        UIImage *allImage = [UIImage imageNamed:@"money.png"];
        allOrder.image = allImage;
        allOrder.contentMode = UIViewContentModeScaleAspectFit;
//        allOrder.backgroundColor = [UIColor redColor];
        [cell addSubview:allOrder];
     
        UILabel *allOrderLabel = [[UILabel alloc] initWithFrame:CGRectMake(allOrder.frame.origin.x + allOrder.frame.size.width + 10, allOrder.frame.origin.y, SCREEN_WIDTH - allOrder.frame.size.width - 30, allOrder.frame.size.height)];
        allOrderLabel.text = @"我的钱包";
        allOrderLabel.font = [UIFont systemFontOfSize:15];
        [cell addSubview:allOrderLabel];
        

    }
    if (indexPath.row == 3) {
        UIImageView *allOrder = [[UIImageView alloc] initWithFrame:CGRectMake(15, 10, 28, 28)];
//        allOrder.backgroundColor = [UIColor redColor];
        UIImage *allImage = [UIImage imageNamed:@"collection.png"];
        allOrder.image = allImage;
        allOrder.contentMode = UIViewContentModeScaleAspectFit;
        [cell addSubview:allOrder];
       
        UILabel *allOrderLabel = [[UILabel alloc] initWithFrame:CGRectMake(allOrder.frame.origin.x + allOrder.frame.size.width + 10, allOrder.frame.origin.y, SCREEN_WIDTH - allOrder.frame.size.width - 30, allOrder.frame.size.height)];
        allOrderLabel.text = @"我的收藏";
       allOrderLabel.font = [UIFont systemFontOfSize:15];
        [cell addSubview:allOrderLabel];
        
  
    }
    if (indexPath.row == 4) {
         UIImageView *allOrder = [[UIImageView alloc] initWithFrame:CGRectMake(15, 10, 28, 28)];
//        allOrder.backgroundColor = [UIColor redColor];
        UIImage *allImage = [UIImage imageNamed:@"good.png"];
        allOrder.image = allImage;
        allOrder.contentMode = UIViewContentModeScaleAspectFit;
        [cell addSubview:allOrder];
        
        UILabel *allOrderLabel = [[UILabel alloc] initWithFrame:CGRectMake(allOrder.frame.origin.x + allOrder.frame.size.width + 10, allOrder.frame.origin.y, SCREEN_WIDTH - allOrder.frame.size.width - 30, allOrder.frame.size.height)];
        allOrderLabel.text = @"给提鲜好评";
      allOrderLabel.font = [UIFont systemFontOfSize:15];
        [cell addSubview:allOrderLabel];
        
  
    }
    if (indexPath.row == 5) {
        UIImageView *allOrder = [[UIImageView alloc] initWithFrame:CGRectMake(15, 10, 28, 28)];
        UIImage *allImage = [UIImage imageNamed:@"set.png"];
        allOrder.image = allImage;
        allOrder.contentMode = UIViewContentModeScaleAspectFit;
        [cell addSubview:allOrder];
      
        UILabel *allOrderLabel = [[UILabel alloc] initWithFrame:CGRectMake(allOrder.frame.origin.x + allOrder.frame.size.width + 10, allOrder.frame.origin.y, SCREEN_WIDTH - allOrder.frame.size.width - 30, allOrder.frame.size.height)];
        allOrderLabel.text = @"设置";
        allOrderLabel.font = [UIFont systemFontOfSize:15];
        [cell addSubview:allOrderLabel];
  

    }
    if (indexPath.row == 6) {

         UIImageView *allOrder = [[UIImageView alloc] initWithFrame:CGRectMake(15, 10, 28, 28)];
//        allOrder.backgroundColor = [UIColor redColor];
        UIImage *allImage = [UIImage imageNamed:@"about.png"];
        allOrder.image = allImage;
        allOrder.contentMode = UIViewContentModeScaleAspectFit;
        [cell addSubview:allOrder];

        UILabel *allOrderLabel = [[UILabel alloc] initWithFrame:CGRectMake(allOrder.frame.origin.x + allOrder.frame.size.width + 10, allOrder.frame.origin.y, SCREEN_WIDTH - allOrder.frame.size.width - 30, allOrder.frame.size.height)];
        allOrderLabel.text = @"关于提鲜";
        allOrderLabel.font = [UIFont systemFontOfSize:15];
        [cell addSubview:allOrderLabel];
    
    }
       return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return SCREEN_WIDTH/3 + 70;
    }
   
      return 50;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"点击");
    if (indexPath.row == 0) {
        LoginViewController *loginVC = [[LoginViewController alloc] init];
        [self.navigationController pushViewController:loginVC animated:YES];
    }
    if (indexPath.row == 6) {
        AboutOurViewController *aboutVC = [[AboutOurViewController alloc] init];
        [self.navigationController pushViewController:aboutVC animated:YES];
    }
    if (indexPath.row == 1) {
        AllOrderViewController *allOrderVC = [[AllOrderViewController alloc] init];
        [self.navigationController pushViewController:allOrderVC animated:YES];
    }
    if (indexPath.row == 2) {
        CouponViewController *couponVC = [[CouponViewController alloc] init];
        [self.navigationController pushViewController:couponVC animated:YES];
    }
    if (indexPath.row == 5) {
        SetViewController *setVC = [[SetViewController alloc] init];
        [self.navigationController pushViewController:setVC animated:YES];
    }
//    if (indexPath.row == 3) {
//        ManageViewController *managerVC = [[ManageViewController alloc] init];
//        [self.navigationController pushViewController:managerVC animated:YES];
//    }
    if (indexPath.row == 3) {
        CollectionViewController *collectVC = [[CollectionViewController alloc] init];
        [self.navigationController pushViewController:collectVC animated:YES];
    }
     [tableView deselectRowAtIndexPath:indexPath animated:YES];
   }

- (void)payTapAction
{
    NSLog(@"待付款");
    PayViewController *payVC = [[PayViewController alloc] init];
    [self.navigationController pushViewController:payVC animated:YES];
    self.tabBarController.tabBar.hidden = NO;
}

- (void)deliverTapAction
{
    NSLog(@"待发货");
    WaitViewController *waitVC = [[WaitViewController alloc] init];
    [self.navigationController pushViewController:waitVC animated:YES];
}

- (void)takeTapAction
{
    NSLog(@"代提货");
    TakeViewController *takeVC = [[TakeViewController alloc] init];
    [self.navigationController pushViewController:takeVC animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
